﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FineUI;
using Maticsoft.BLL;
using Maticsoft.Model;

namespace FineUI.Examples
{
    public partial class student_course_Information : System.Web.UI.Page
    {
        protected DataSet LoadCourseInform()
        {
            if (Session["UserName"] == null)
            {
                Response.Redirect("~/login.aspx");

            }

            string currentS_Id = Session["UserName"].ToString();


            DataSet DSStudentCourse = new DataSet();
            DataTable SelectCourseTable = new DataTable();

            SelectCourseTable.Columns.Add(new DataColumn("星期一", typeof(string)));
            SelectCourseTable.Columns.Add(new DataColumn("星期二", typeof(string)));
            SelectCourseTable.Columns.Add(new DataColumn("星期三", typeof(string)));
            SelectCourseTable.Columns.Add(new DataColumn("星期四", typeof(string)));
            SelectCourseTable.Columns.Add(new DataColumn("星期五", typeof(string)));
            SelectCourseTable.Columns.Add(new DataColumn("星期六", typeof(string)));
            SelectCourseTable.Columns.Add(new DataColumn("星期天", typeof(string)));

            for (int i = 1; i <= 11; i++)
            {
                DataRow currentRow = SelectCourseTable.NewRow();
                SelectCourseTable.Rows.Add(currentRow);
            }

            //添加表
            DSStudentCourse.Tables.Add(SelectCourseTable);

            Maticsoft.BLL.SelectCourse SelectCourse = new Maticsoft.BLL.SelectCourse();
            DataSet currentDataSet = SelectCourse.GetCourseInform(currentS_Id);


            //将信息写入表
            for (int i = 0; i < currentDataSet.Tables[0].Rows.Count; i++)
            {
                string currentTime = currentDataSet.Tables[0].Rows[i]["TC_Date_Time"].ToString();
                string currentWeek = currentDataSet.Tables[0].Rows[i]["TC_Date_Day"].ToString();
                string currentTeaClassName = currentDataSet.Tables[0].Rows[i]["TC_Name"].ToString();
                int index = 0;
                try
                {
                    index = Convert.ToInt32(currentTime);
                }
                catch (Exception)
                {


                }

                if (index >= 1)
                {
                    DSStudentCourse.Tables[0].Rows[index - 1][currentWeek] = currentTeaClassName;
                }

            }

            //  if (!IsPostBack)//
            //  {
            DataView view1 = DSStudentCourse.Tables[0].DefaultView;
            Grid2.DataSource = view1;
            Grid2.DataBind();

            //  }


            return DSStudentCourse;


        }

        protected void ExistsPermiss(string P_Id, string P_Status)
        {
            Maticsoft.BLL.Permissions PM = new Maticsoft.BLL.Permissions();
            if (!PM.ExistsPermiss(P_Id, P_Status))
            {
                Response.Redirect("~/user_no_permission.aspx");
            }

        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserName"] == null)
            {
                Response.Redirect("~/login.aspx");
            }
            ExistsPermiss("S002", "已授权");
            LoadCourseInform();
        }

        protected void Grid2_RowCommand(object sender, GridCommandEventArgs e)
        {

        }

        protected void Grid2_PageIndexChange(object sender, GridPageEventArgs e)
        {
            Grid2.PageIndex = e.NewPageIndex;
            LoadCourseInform();
        }
    }
}